<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>upload模块快速使用</title>
  <link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui/css/layui.css" />
</head>
<body>
 
  <button type="button" class="layui-btn" id="test1">
    <i class="layui-icon">&#xe67c;</i>上传图片/文件
  </button>
  
  <script src="https://www.layuicdn.com/layui/layui.js"></script>
  <script>
  layui.use('upload', function(){
    var upload = layui.upload;
    
    //执行实例
    var uploadInst = upload.render({
      elem: '#test1' //绑定元素
    
      ,accept: 'file' //上传类型自行改写 指定允许上传时校验的文件类型，可选值有：images（图片）、file（所有文件）、video（视频）、audio（音频）
      ,url: '/addons/aliossapiupload/index/upload'//上传接口默认 /addons/aliossapiupload/index/upload  
      ,done: function(res){
        //上传完毕回调

        var content = '完整路径:\n'+res.data.fullurl+'\n相对路径：\n'+res.data.url ;
        document.getElementById('content').value = content;

        document.getElementById('img').src = res.data.fullurl;

      }
      ,error: function(){
        //请求异常回调
        // alert(res.msg);
        var content = '错误消息：'+res.data.msg ;
        document.getElementById('content').value = content;
      }
    });
  });
  </script>

  <div>
    <textarea name="content" id="content" cols="50" rows="20"></textarea>
  </div>
  <div>
    <img src="" id="img" alt="">
  </div>
  
</body>
</html>